Home Page

library(tidycensus)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
fl_education_data <- get_acs(
  geography = "tract",  # Use "block group" for block group level
  variables = "B15003_022",  # Example: Bachelor's degree or higher
  state = "FL",  # Florida
  year = 2021,  # Specify the year
  survey = "acs5",  # 5-year ACS data
  geometry = TRUE  # Set to TRUE if you want spatial data
)
Getting data from the 2017-2021 5-year ACS
fl_education_data <- fl_education_data %>%
  rename(
    Tract = NAME,
    Education_Variable = variable,
    Estimate = estimate,
    Margin_of_Error = moe
  )

# Add a new column for popup text (optional but useful for interactivity)
fl_education_data <- fl_education_data %>%
  mutate(
    Popup_Text = paste(
      "Tract: ", Tract, "<br>",
      "Estimate: ", Estimate, "<br>",
      "Margin of Error: ", Margin_of_Error
    )
  )
# Define a color palette based on the Estimate values
pal <- colorNumeric(
  palette = "viridis",  # You can use "viridis", "plasma", or other color schemes
  domain = fl_education_data$Estimate
)

# Create the interactive map
leaflet_map <- leaflet(fl_education_data) %>%
  addTiles() %>%  # Add base map tiles
  addPolygons(
    color = ~pal(Estimate),  # Color polygons based on Estimate
    weight = 1,              # Border thickness
    opacity = 1,             # Border opacity
    fillOpacity = 0.7,       # Fill opacity
    popup = ~Popup_Text,     # Popup text when clicking on a tract
    highlightOptions = highlightOptions(
      weight = 2,            # Highlight border thickness
      color = "white",       # Highlight border color
      fillOpacity = 0.9,     # Highlight fill opacity
      bringToFront = TRUE    # Bring highlighted tract to front
    )
  ) %>%
  addLegend(
    position = "bottomright",  # Position of the legend
    pal = pal,                 # Color palette
    values = ~Estimate,        # Values for the legend
    title = "Estimate of Bachelor's Degree or Higher"  # Legend title
  )
Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
Need '+proj=longlat +datum=WGS84'
# Display the map
leaflet_map